﻿/*
* 
*
* 功 能： N/A
* 类 名： BDJTWELL
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* 
*/
using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;

using DQYT.HTDZ.IDAL;
using Maticsoft.DBUtility;
using DQYT.HTDZ.Model;

namespace DQYT.HTDZ.OracleDAL
{
	/// <summary>
	/// 数据访问类:BDJTWELL
	/// </summary>
	public partial class BDJTWELLDAL:IBDJTWELL
	{
		public BDJTWELLDAL()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string WELLID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from BDJTWELL");
			strSql.Append(" where WELLID=:WELLID ");
			OracleParameter[] parameters = {
					new OracleParameter(":WELLID", OracleType.VarChar,30)			};
			parameters[0].Value = WELLID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(BDJTWELLModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into BDJTWELL(");
			strSql.Append("GQID,WELLID,TYJM,BZJM,KZRQ,DLWZ,WD,JD,SFPTJ,SFHSJ,SFHDJ,SS)");
			strSql.Append(" values (");
			strSql.Append(":GQID,:WELLID,:TYJM,:BZJM,:KZRQ,:DLWZ,:WD,:JD,:SFPTJ,:SFHSJ,:SFHDJ,:SS)");
			OracleParameter[] parameters = {
					new OracleParameter(":GQID", OracleType.VarChar,30),
					new OracleParameter(":WELLID", OracleType.VarChar,30),
					new OracleParameter(":TYJM", OracleType.VarChar,30),
					new OracleParameter(":BZJM", OracleType.VarChar,30),
					new OracleParameter(":KZRQ", OracleType.DateTime),
					new OracleParameter(":DLWZ", OracleType.VarChar,30),
					new OracleParameter(":WD", OracleType.Float,22),
					new OracleParameter(":JD", OracleType.Float,22),
					new OracleParameter(":SFPTJ", OracleType.Number,4),
					new OracleParameter(":SFHSJ", OracleType.Number,4),
					new OracleParameter(":SFHDJ", OracleType.Number,4),
					new OracleParameter(":SS", OracleType.Float,22)};
			parameters[0].Value = model.GQID;
			parameters[1].Value = model.WELLID;
			parameters[2].Value = model.TYJM;
			parameters[3].Value = model.BZJM;
			parameters[4].Value = model.KZRQ;
			parameters[5].Value = model.DLWZ;
			parameters[6].Value = model.WD;
			parameters[7].Value = model.JD;
			parameters[8].Value = model.SFPTJ;
			parameters[9].Value = model.SFHSJ;
			parameters[10].Value = model.SFHDJ;
			parameters[11].Value = model.SS;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(BDJTWELLModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update BDJTWELL set ");
			strSql.Append("GQID=:GQID,");
			strSql.Append("TYJM=:TYJM,");
			strSql.Append("BZJM=:BZJM,");
			strSql.Append("KZRQ=:KZRQ,");
			strSql.Append("DLWZ=:DLWZ,");
			strSql.Append("WD=:WD,");
			strSql.Append("JD=:JD,");
			strSql.Append("SFPTJ=:SFPTJ,");
			strSql.Append("SFHSJ=:SFHSJ,");
			strSql.Append("SFHDJ=:SFHDJ,");
			strSql.Append("SS=:SS");
			strSql.Append(" where WELLID=:WELLID ");
			OracleParameter[] parameters = {
					new OracleParameter(":GQID", OracleType.VarChar,30),
					new OracleParameter(":TYJM", OracleType.VarChar,30),
					new OracleParameter(":BZJM", OracleType.VarChar,30),
					new OracleParameter(":KZRQ", OracleType.DateTime),
					new OracleParameter(":DLWZ", OracleType.VarChar,30),
					new OracleParameter(":WD", OracleType.Float,22),
					new OracleParameter(":JD", OracleType.Float,22),
					new OracleParameter(":SFPTJ", OracleType.Number,4),
					new OracleParameter(":SFHSJ", OracleType.Number,4),
					new OracleParameter(":SFHDJ", OracleType.Number,4),
					new OracleParameter(":SS", OracleType.Float,22),
					new OracleParameter(":WELLID", OracleType.VarChar,30)};
			parameters[0].Value = model.GQID;
			parameters[1].Value = model.TYJM;
			parameters[2].Value = model.BZJM;
			parameters[3].Value = model.KZRQ;
			parameters[4].Value = model.DLWZ;
			parameters[5].Value = model.WD;
			parameters[6].Value = model.JD;
			parameters[7].Value = model.SFPTJ;
			parameters[8].Value = model.SFHSJ;
			parameters[9].Value = model.SFHDJ;
			parameters[10].Value = model.SS;
			parameters[11].Value = model.WELLID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string WELLID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDJTWELL ");
			strSql.Append(" where WELLID=:WELLID ");
			OracleParameter[] parameters = {
					new OracleParameter(":WELLID", OracleType.VarChar,30)			};
			parameters[0].Value = WELLID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string WELLIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDJTWELL ");
			strSql.Append(" where WELLID in ("+WELLIDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BDJTWELLModel GetModel(string WELLID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select GQID,WELLID,TYJM,BZJM,KZRQ,DLWZ,WD,JD,SFPTJ,SFHSJ,SFHDJ,SS from BDJTWELL ");
			strSql.Append(" where WELLID=:WELLID ");
			OracleParameter[] parameters = {
					new OracleParameter(":WELLID", OracleType.VarChar,30)			};
			parameters[0].Value = WELLID;

			BDJTWELLModel model=new BDJTWELLModel();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BDJTWELLModel DataRowToModel(DataRow row)
		{
			BDJTWELLModel model=new BDJTWELLModel();
			if (row != null)
			{
				if(row["GQID"]!=null)
				{
					model.GQID=row["GQID"].ToString();
				}
				if(row["WELLID"]!=null)
				{
					model.WELLID=row["WELLID"].ToString();
				}
				if(row["TYJM"]!=null)
				{
					model.TYJM=row["TYJM"].ToString();
				}
				if(row["BZJM"]!=null)
				{
					model.BZJM=row["BZJM"].ToString();
				}
				if(row["KZRQ"]!=null && row["KZRQ"].ToString()!="")
				{
					model.KZRQ=DateTime.Parse(row["KZRQ"].ToString());
				}
				if(row["DLWZ"]!=null)
				{
					model.DLWZ=row["DLWZ"].ToString();
				}
				if(row["WD"]!=null && row["WD"].ToString()!="")
				{
					model.WD=decimal.Parse(row["WD"].ToString());
				}
				if(row["JD"]!=null && row["JD"].ToString()!="")
				{
					model.JD=decimal.Parse(row["JD"].ToString());
				}
				if(row["SFPTJ"]!=null && row["SFPTJ"].ToString()!="")
				{
					model.SFPTJ=decimal.Parse(row["SFPTJ"].ToString());
				}
				if(row["SFHSJ"]!=null && row["SFHSJ"].ToString()!="")
				{
					model.SFHSJ=decimal.Parse(row["SFHSJ"].ToString());
				}
				if(row["SFHDJ"]!=null && row["SFHDJ"].ToString()!="")
				{
					model.SFHDJ=decimal.Parse(row["SFHDJ"].ToString());
				}
				if(row["SS"]!=null && row["SS"].ToString()!="")
				{
					model.SS=decimal.Parse(row["SS"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select GQID,WELLID,TYJM,BZJM,KZRQ,DLWZ,WD,JD,SFPTJ,SFHSJ,SFHDJ,SS ");
			strSql.Append(" FROM BDJTWELL ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM BDJTWELL ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.WELLID desc");
			}
			strSql.Append(")AS Row, T.*  from BDJTWELL T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "BDJTWELL";
			parameters[1].Value = "WELLID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

